package com.linx.common.core.enums.device;

import com.linx.common.core.domain.model.DictEnumBody;
import lombok.Getter;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;


/**
 * 摄像机类型（0-固定枪机，1-有云台枪机，2-球机，3-半球-固定摄像机，4-筒机）
 */
@Getter
public enum CameraTypeEnum {

    FIXED_BULLET_CAMERA("0", 0, "固定枪机"),
    PTZ_BULLET_CAMERA("1", 1, "有云台枪机"),
    BALL_CAMERA("2", 2, "球机"),
    HEMISPHERE_FIXED_CAMERA("3", 3, "半球-固定摄像机"),
    COMPACT_CAMERA("4",  4, "筒机"),
    ;

    private final String code;

    private final Integer sort;

    private final String label;

    CameraTypeEnum(String code, Integer sort, String label) {
        this.code = code;
        this.sort = sort;
        this.label = label;
    }

    /**
     *  获取枚举列表
     */
    public static List<DictEnumBody> list() {
        List<DictEnumBody> libEnumVOList = new ArrayList<>();
        Class<CameraTypeEnum> enumClass = CameraTypeEnum.class;

        try {
            Method getCode = enumClass.getMethod("getCode");
            Method getSort = enumClass.getMethod("getSort");
            Method getLabel = enumClass.getMethod("getLabel");

            //  通过反射取出Enum所有常量的属性值
            for (CameraTypeEnum enumConstant: enumClass.getEnumConstants()) {
                String code = (String) getCode.invoke(enumConstant);
                Integer sort = (Integer) getSort.invoke(enumConstant);
                String label = (String) getLabel.invoke(enumConstant);

                libEnumVOList.add(new DictEnumBody(code, sort, label, null));
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return libEnumVOList;
    }

    /**
     * 根据code获取label
     */
    public static String getLabelByCode(String code) {
        for (CameraTypeEnum item: CameraTypeEnum.values()) {
            if (item.getCode().equals(code)) {
                return item.getLabel();
            }
        }
        return null;
    }


}
